package com.sgmw.sales.tool.kong.sign.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {
	public static String md5(String param) {
		if (param == null || param.isEmpty()) {
			throw new IllegalArgumentException("param can not be null");
		}
		try {
			byte[] bytes = param.getBytes("utf-8");
			final MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(bytes);
			
			sun.misc.BASE64Encoder base64 = new sun.misc.BASE64Encoder();
			return base64.encode(md.digest());
		} catch (final NoSuchAlgorithmException e) {
			throw new IllegalArgumentException("unknown algorithm MD5");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
}